FreeMarker空值异常:

您所在的位置:网站首页 sharpshooters refer to those FreeMarker空值异常:

FreeMarker空值异常:

2023-09-24 18:04| 来源: 网络整理| 查看: 265

freemarker 报错: username:'FreeMarker template error (DEBUG mode; use RETHROW in production!): The following has evaluated to null or missing: ==> profile [in template “inc/layout.ftl” at line 28, column 21] Tip: If the failing expression is known to legally refer to something that’s sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use when-presentwhen-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??

大致意思是某个对象为null或者缺失,导致表达式不合法,可以指定默认值,指定方式是:myOptionalVar!myDefault 或者when-presentwhen-missing. (这仅仅覆盖最后一个表达式,如果要覆盖整个表达式使用:(myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??) 我的错误在:

layui.cache.user = { username:'${profile.username!"游客"}' ,uid:${profile.id!"-1"} ,avatar: '${profile.avatar!"/res/images/avatar/00.jpg"}' ,experience: 83 ,sex: '${profile.sex!"男"}' };

提示==> profile [in template “inc/layout.ftl” at line 28, column 21]为空,于是修改为带括号的表达式解决问题:

layui.cache.user = { username:'${(profile.username)!"游客"}' ,uid:${(profile.id)!"-1"} ,avatar: '${(profile.avatar)!"/res/images/avatar/00.jpg"}' ,experience: 83 ,sex: '${(profile.sex)!"男"}' };

不在报错,解决问题。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3